package com.java.dp.proxy;

import java.lang.reflect.InvocationHandler;
import java.lang.reflect.Method;

/**
 * @Author lizhilong
 * @create 2019/12/3 14:14
 * @desc
 */
public class JDKProxy implements InvocationHandler {

    private  Object object;

    public JDKProxy(Object object){
        this.object = object;
    }

    @Override
    public Object invoke(Object proxy, Method method, Object[] args) throws Throwable {
        beforeBuy();
        Object result = method.invoke(object,args);
        afterBuy();
        return result;
    }

    private void  beforeBuy(){
        System.out.println("购买火车票之前需要在携程app预约");
    }

    private  void  afterBuy(){
        System.out.println("购买成功要支付手续费");
    }
}
